package com.visionet.school.app.web.repository.wechat;

import com.visionet.school.app.web.entity.wechat.Menu;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by hxpeng on 2017/3/1.
 */

@Repository
public interface MenuRepository extends PagingAndSortingRepository<Menu,String>,JpaSpecificationExecutor<Menu> {

    @Query("from Menu where isDeleted='0'")
    public List<Menu> findCmWxmenusList();

//    public Menu findOneCmWxmenusById(String id);
//
//    public boolean checkCmWxmenusIsExits(String id);

    @Query(value="select * from (select * from t_wechat_menu where is_deleted='0' and menu_status<>2 and parent_id is null order by update_Date desc)tmp  where rownum<=3",nativeQuery=true)
    public List<Menu> findShowParent();

    @Query(value="select * from (select * from t_wechat_menu where is_deleted='0' and menu_status<>2 and parent_id=?1 order by update_Date desc)tmp  where rownum<=5",nativeQuery=true)
    public List<Menu> findChildMenus(String parentid);


}
